package com.zhangwei.day31volley.utils;

import android.graphics.Bitmap;
import android.support.v4.util.LruCache;

import com.android.volley.toolbox.ImageLoader;

/**
 * @author zhangwei
 * @version V1.0
 * @Title: Advanced
 * @Package com.zhangwei.day31volley
 * @Description:
 * @date 15/10/16 上午11:21
 */

/**
 *
 */
public class AppImageCache implements ImageLoader.ImageCache {
    private static AppImageCache imageCache;
    private static LruCache<String, Bitmap> lruCache;
    private static ImageLoader imageLoader;


    private AppImageCache() {
        lruCache = new LruCache<String, Bitmap>(4 * 1024 * 1024) {
            @Override
            protected int sizeOf(String key, Bitmap value) {
                return value.getRowBytes() * value.getHeight();
            }
        };
    }

    public static AppImageCache getInstance() {
        if (imageCache == null) {
            imageCache = new AppImageCache();
        }
        return imageCache;
    }

    @Override
    public Bitmap getBitmap(String url) {
        return lruCache.get(url);
    }

    @Override
    public void putBitmap(String url, Bitmap bitmap) {
        lruCache.put(url, bitmap);
    }



}
